package com.ytzl.itrip.service.userinfo.impl;

import com.ytzl.itrip.dao.auto.userinfo.ItripUserLinkUserMapper;
import com.ytzl.itrip.pojo.po.userinfo.ItripUserLinkUser;
import com.ytzl.itrip.pojo.vo.userinfo.OftenLinkUserVO;
import com.ytzl.itrip.service.userinfo.OftenLinkUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Date;

/**
 * Description: 本类用于
 * Created by gengshu on 2019/12/30 17:44
 */
@Service
@Slf4j
public class OftenLinkUserServiceImpl implements OftenLinkUserService {
    //注入ItripUserLinkUserMapper对象
    @Autowired
    private ItripUserLinkUserMapper itripUserLinkUserMapper;

    /**
     * 查询常用联系人
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public List<ItripUserLinkUser> queryItripUserLinkUserById(@Param("id") Integer id, @Param("name") String name) throws Exception {
        List<ItripUserLinkUser> list = itripUserLinkUserMapper.queryItripUserLinkUserMapperById(id, name);
        if (list != null) {
            return list;
        } else {
            return null;
        }


    }

    /**
     * 添加常用联系人
     * @param oftenLinkUserVo
     * @param userId
     * @return
     * @throws Exception
     */
    @Override
    public int addOftenLinkUser(OftenLinkUserVO oftenLinkUserVo, long userId) throws Exception {
        ItripUserLinkUser itripUserLinkUser=new ItripUserLinkUser();
        itripUserLinkUser.setLinkUserName(oftenLinkUserVo.getLinkUserName());
        itripUserLinkUser.setLinkIdCard(oftenLinkUserVo.getLinkIdCard());
        itripUserLinkUser.setLinkPhone(oftenLinkUserVo.getLinkPhone());
        itripUserLinkUser.setUserId((int) userId);
        itripUserLinkUser.setCreatedBy(userId);
        itripUserLinkUser.setCreationDate(new Date());
        return itripUserLinkUserMapper.addOftenLinkUser(itripUserLinkUser);
    }

    /**
     * 修改常用联系人
     * @param oftenLinkUserVO
     * @return
     * @throws Exception
     */
    @Override
    public Integer updateOftenLinkUser(OftenLinkUserVO oftenLinkUserVO) throws Exception {
        ItripUserLinkUser itripUserLinkUser = new ItripUserLinkUser();
        itripUserLinkUser.setLinkIdCard(oftenLinkUserVO.getLinkIdCard());
        itripUserLinkUser.setLinkPhone(oftenLinkUserVO.getLinkPhone());
        itripUserLinkUser.setLinkUserName(oftenLinkUserVO.getLinkUserName());
        itripUserLinkUser.setId(oftenLinkUserVO.getId());
        return itripUserLinkUserMapper.updateOftenLinkUser(itripUserLinkUser);
    }
    /**
     * 根据id删除常用联系人
     * @param id 联系人id
     * @return 删除结果
     * @throws Exception 抛出异常
     */
    @Override
    public boolean deleteLinkUserById(@Param("ids") Integer id) throws Exception {
        int result = itripUserLinkUserMapper.deleteLinkUserById(id);
        if (result == 1){
            return true;
        }else {
            return false;
        }
    }
}
